package com.wyj.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * TODO: 登录拦截器
 *
 * @author wuyijie
 * @date 2021/12/20 5:51 下午
 */
@Component
@Slf4j
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //判断session是否存在，没有则返回false；
        HttpSession session = request.getSession(false);
        if (null == session){
            return false;
        }
        String sessionId = session.getId();
        log.info("LoginInterceptor sessionId={}", sessionId);
        return true;
    }

}
